home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 10 Scripting / 02 Berger / scc / PTNode.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-15  |  1.1 KB  |  64 lines

  1. #include <stdio.h>
  2.  
  3. #include "PTNode.H"
  4.  
  5.  
  6. void
  7. PTNode::Dump() const
  8. {
  9.   Dump_Internal( 0 );
  10.   printf( "\n" );
  11.  
  12. }
  13.  
  14.  
  15. void
  16. PTNode::Dump_Internal( int indent ) const
  17. {
  18.   int c = 0;
  19.   for ( ; c < indent; c += 2 )
  20.     printf( " |" );
  21.  
  22.   printf( " +-- %s\n", GetName().c_str() );
  23.  
  24.  
  25.   NodeList::const_iterator i = GetChildrenBegin();
  26.   NodeList::const_iterator end = GetChildrenEnd();
  27.  
  28.   indent += 2;
  29.  
  30.   for ( ; i != end; ++i ) {
  31.     PTNodePtr node = *i;
  32.  
  33.     // It is okay for some nodes to have NULL pointers in their list of
  34.     // children.  This just means that the optional child is not specified.
  35.     if ( node == NULL )
  36.       continue;
  37.  
  38.     node->Dump_Internal( indent );
  39.   }
  40.  
  41.   indent -= 2;
  42. }
  43.  
  44.  
  45.  
  46. // When dumping the parse tree, it is useful to see what the actual constant
  47. // number.  Make sure to add its value to the name string.
  48. string
  49. ConstantNode::GetName() const
  50. {
  51.   char name[64];
  52.   sprintf( name, "Constant %d", m_value );
  53.  
  54.   return name;
  55. }
  56.  
  57.  
  58.  
  59. string
  60. IdentifierNode::GetName() const
  61. {
  62.   return "Identifier " + m_name;
  63. }
  64.